import type {
  ConsultOrderListParams,
  FollowType,
  KnowledgeParams,
  OrderPreParams,
  PartialConsult
} from '@/types/consult'
import request from '@/utils/request'

export const getKnowledgePageAPI = (params: KnowledgeParams) => {
  return request({ url: 'patient/home/knowledge', params })
}

export const getDoctorsAPI = (current = '1', pageSize = '5') => {
  return request({ url: 'home/page/doc', params: { current, pageSize } })
}

export const followAPI = (id: string, type: FollowType = 'doc') => {
  return request({ url: 'like', method: 'post', data: { id, type } })
}

export const getDepsAPI = () => request({ url: 'dep/all' })

export const uploadAPI = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request({ url: 'upload', method: 'post', data: fd })
}

export const getPatientDetailAPI = (id: string) => {
  return request({ url: `patient/info/${id}` })
}

export const getPreOrderAPI = (params: OrderPreParams) => {
  return request({ url: 'patient/consult/order/pre', params })
}

export const createOrderAPI = (data: PartialConsult) => {
  return request({ url: '/patient/consult/order', method: 'POST', data })
}

type PayParam = {
  paymentMethod: number
  orderId: string
  payCallback: string
}
export const consultPayAPI = (data: PayParam) => {
  return request({ url: 'patient/consult/pay', method: 'post', data })
}

export const getOrederDetailAPI = (orderId: string) => {
  return request({
    url: 'patient/consult/order/detail',
    params: { orderId }
  })
}

export const getPrePicAPI = (id: string) => {
  return request({ url: `patient/consult/prescription/${id}` })
}

type EvaluateOrderParams = {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}

export const evaluateOrderAPI = (data: EvaluateOrderParams) => {
  return request({ url: '/patient/order/evaluate', method: 'POST', data })
}

export const getOrderRecordsAPI = (params: ConsultOrderListParams) => {
  return request({ url: '/patient/consult/order/list', params })
}
export const cancelOrderAPI = (id: string) => {
  return request({ url: `patient/order/cancel/${id}`, method: 'put' })
}

export const delOrderAPI = (id: string) => {
  return request({ url: `patient/order/${id}`, method: 'delete' })
}
